var currentTreeNode = null;
var treeObj;

$(document).ready(function() {
	treeObj = mini.get("tree");
	initTree();
});

/***
 * 加载机构分类
 * */
function initTree() {
	Tree.getTree(treeObj, 'sysOrgCate!list.do', "socId", "parentId");
}

/***
 * 点击机构分类，加载功能树
 * */
function treeselected(e) {
	var tree = e.sender;
	var node = e.node;
	currentTreeNode = node;
    Tree.getTree(mini.get("treeFun"), 'sysCateFunction!getCateFunctionTree.do?sysCateFunction.functionCate=' + currentTreeNode.socId, "functionId", "parentId");
	$("#edit_node").css("display", "block");
	$("#sBtn").css("display", "block");
}

/***
 * 保存选择的功能树节点
 * */
function editOrgData() {
	var currentCategory = currentTreeNode.socId;
	var treeFunObj = mini.get("treeFun");
	var nodes = treeFunObj.getCheckedNodes(true);
	var functionId="";
	for(var i = 0; i < nodes.length; i++) {
		var curretnNode = nodes[i];
        functionId = functionId +","+curretnNode.functionId;
	}
	var formData = {
		'sysCateFunction.functionId': functionId.substring(1),
		'sysCateFunction.functionCate': currentCategory
	};
    ActHttpRequest("sysCateFunction!add.do", formData, function(data) {
		if(data.OK == "OK") {
			var e = {
				sender: treeObj,
				node: currentTreeNode
			}
			treeselected(e);
			mini.alert("保存成功");
		} else {
			mini.alert(data.message);
		}
	}, null, null, null, '保存中。。。',true);
}

function refershTree() {
	initTree();
	$("#edit_node").css("display", "none");
}
